<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/pages/common/component.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>修改资源信息</title>
<script type="text/javascript">

$(document).ready(function() {
	// 开始时间
	configDate('resource_startDate', '<fmt:formatDate value="${objPlanResourceVO.startDate }" pattern="yyyy-MM-dd "/>', 'yy-mm-dd');
	// 结束时间
	configDate('resource_endDate', '<fmt:formatDate value="${objPlanResourceVO.endDate }" pattern="yyyy-MM-dd "/>', 'yy-mm-dd');
    // 校验主表单
    $("#planResourceForm").validationEngine();
});

// 返回账户列表
function back2list(){
	if(confirm("数据没有保存!确认将丢失当前表单数据!")){
		window.location.href = "planResourceAction.do?method=list"
	}else{
		return ;
	}
}


// 新增行动

function createAction(){
	// 打开层页面加载添加Action的新增页面
	$('#create_action_container').dialog({
		modal: true,
		autoOpen: false,
		resizable:false, 
		title: '为资源添加行动',
		width: 800,
		height: 600
	});
	$('#create_action_container').dialog('open');
	$('#create_action_container').load('/venus/planActionAction.do?method=create');
	
}
// 插入行动,并且把行动显示到资源页面
function insertAction(){
	// ajax插入Action到数据库
	$.ajax({   
	    type: "POST",
	    url: "planActionAction.do",
	    data: decodeURIComponent($('#planActionForm').serialize(),true),
	    dataType:"json",
	    async: false,
	    cache: false,
	    success: function(json){
	    	// 关闭子层页面
	    	
	    	// 显示到当前'行动列表'中
	    	insertActionRow2Tab(json.startDate, json.endDate, json.doneDate, json.status, json.priority, json.curLevel);
	    },
	    error: function(msg){
	       	alert("新增行动出错!请稍后再试!");
	    }
   	});
}

function insertActionRow2Tab(startDate, endDate, doneDate, status, priority, curLevel){
	// 状态
	var strStatus = "";
	if('<%=Constants.PLAN_STATUS_NEW%>' == status){
		strStatus = "未开始";
	}else if('<%=Constants.PLAN_STATUS_DOING%>' == status){
		strStatus = "进行中";
	}else if('<%=Constants.PLAN_STATUS_PAUSE%>' == status){
		strStatus = "暂定";
	}else if('<%=Constants.PLAN_STATUS_DONE%>' == status){
		strStatus = "完成";
	}else if('<%=Constants.PLAN_STATUS_BREAK%>' == status){
		strStatus = "作废";
	}else{
		alert("没有对应的状态值!STATUS="+status);
	}
	// 优先级
	var strPriority = "";
	if('<%=Constants.PLAN_PRIORITY_LOW%>' == priority){
		strPriority = "低";
	}else if('<%=Constants.PLAN_PRIORITY_MIDDLE%>' == priority){
		strPriority = "中";
	}else if('<%=Constants.PLAN_PRIORITY_HIGH%>' == priority){
		strPriority = "高";
	}else{
		this.log.error("没有对应的优先级值!PRIORITY="+priority);
	}
   	
   	var tr = $('#action_list_head');
	// 动态添加tr的ID索引
	var idx = $('#action_list_tab tr').length - 1;
	tr.after(
   		"<tr align='center' bgcolor='#FFFFFF' onMouseMove=\"javascript:this.bgColor='#FAFAF1'\" onMouseOut=\"javascript:this.bgColor='#FFFFFF'\" height='22'>"+
			"<td><input id=startDate_"+idx+" value='"+startDate+"' style='width:100%' /></td>"+
			"<td><input id=endDate_"+idx+" value='"+endDate+"' style='width:100%' /></td>"+
			"<td><input id=doneDate_"+idx+" value='"+doneDate+"' style='width:100%' /></td>"+
			"<td>"+strStatus+"</td>"+
			"<td>"+strPriority+"</td>"+
			"<td>"+curLevel+"</td>"+
		"</tr>"
   	);
   	// 时间选择
   	//alert($('#startDate_'+idx));
	configDate('startDate_'+idx, startDate.substring(0, 10), 'yy-mm-dd');
	configDate('endDate_'+idx, endDate.substring(0, 10), 'yy-mm-dd');
	configDate('doneDate_'+idx, doneDate.substring(0, 10), 'yy-mm-dd');
}

</script>	
	
  </head>
  
  <body>
   
   <html:form styleId="planResourceForm" method="post" action="planResourceAction.do">
    <input type="hidden" name="method" value="update"/>
    <input type="hidden" id="resource_planResourceId" name="planResourceId" value="${objPlanResourceVO.planResourceId }"/>
    <br/><br/>
    <table width="40%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">
		<tr align="center" bgcolor="#FAFAF1" height="22">
			<td colspan="2"><b>修改目标</b></td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td width="10%">资源名称</td>
			<td width="30%">
				<input id="planResourceName" name="planResourceName" style='width:40%;' value="${objPlanResourceVO.planResourceName }"/>
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td width="10%">资源类型</td>
			<td width="30%">
				<select name="resourceType" style="width:40%;">
					<option value="<%=Constants.PLAN_RESOURCE_SKILL%>" ${objPlanResourceVO.resourceType==1 ? 'selected' : ''}>技能(SKILL)</option>
					<option value="<%=Constants.PLAN_RESOURCE_FUND%>" ${objPlanResourceVO.resourceType==2 ? 'selected' : ''}>资金(FUND)</option>
					<option value="<%=Constants.PLAN_RESOURCE_CONTACT%>" ${objPlanResourceVO.resourceType==3 ? 'selected' : ''}>人脉(CONTACT)</option>
				</select>
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td width="10%">属性类型</td>
			<td width="30%">
				<select name="property" style="width:40%;">
					<option value="<%=Constants.PLAN_RESOURCE_PROPERTY_ONETIME%>" ${objPlanResourceVO.property==2 ? 'selected' : ''}>一次性(ONETIME)</option>
					<option value="<%=Constants.PLAN_RESOURCE_PROPERTY_FOREVER%>" ${objPlanResourceVO.property==1 ? 'selected' : ''}>永久性(FOREVER)</option>
				</select>
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td>开始日期</td>
			<td>
				<input id="resource_startDate" name="startDate" style='width:40%;' readonly/>
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td>结束日期</td>
			<td>
				<input id="resource_endDate" name="endDate" style='width:40%;' readonly/>
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td>优先级</td>
			<td>
				<select name="priority" id="priority" style="width:40%;">
					<option value="<%=Constants.PLAN_PRIORITY_LOW %>" ${objPlanResourceVO.priority==1?'selected':'' }>低</option>
					<option value="<%=Constants.PLAN_PRIORITY_MIDDLE %>" ${objPlanResourceVO.priority==2?'selected':'' }>中</option>
					<option value="<%=Constants.PLAN_PRIORITY_HIGH %>" ${objPlanResourceVO.priority==3?'selected':'' }>高</option>
				</select>
			</td>
		</tr>
		<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td>备注</td>
			<td>
				<input name="note" id="note" value="${objPlanResourceVO.note }" style='width:40%;'/>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<html:submit value="提交"></html:submit>
				&nbsp;&nbsp;&nbsp;
				<input type="button" value="返回" onclick="back2list();"> 
			</td>
		</tr>
    </table>
   </html:form> 
    
    <br/>
    <table id="action_list_tab" width="50%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">
		<tr align="center" bgcolor="#FAFAF1" height="22">
			<td colspan="7"><b onclick="createAction()">增加行动</b></td>
		</tr>
		<tr id="action_list_head" align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
			<td width="10%">开始日期</td>
			<td width="10%">结束日期</td>
			<td width="10%">完成日期</td>
			<td width="6%">当前状态</td>
			<td width="6%">优先级</td>
			<td width="10%">等级</td>
		</tr>
		<c:forEach var="planAction" items="${objPlanResourceVO.planActionList}" varStatus="status">
			<script>insertActionRow2Tab('<c:out value="${planAction.startDate}"/>', '<c:out value="${planAction.endDate}"/>', '<c:out value="${planAction.doneDate}"/>', '<c:out value="${planAction.status}"/>', '<c:out value="${planAction.priority}"/>', '<c:out value="${planAction.curLevel}"/>')</script>
		</c:forEach>
	</table>
   <div id="create_action_container" style="width: 600px; height: 400px; margin: 0 auto"></div>
  </body>
</html>
